﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplicationTest
{
    class Program
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

        [StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;                             //最左坐标
            public int Top;                             //最上坐标
            public int Right;                           //最右坐标
            public int Bottom;                        //最下坐标
        }

        static void Main(string[] args)
        {
            var awin = GetForegroundWindow();    //获取当前窗口句柄
            RECT rect = new RECT();
            GetWindowRect(awin, ref rect);
            rect.Right = 500;
            rect.Left = 0;

            int width = rect.Right - rect.Left;                        //窗口的宽度
            int height = rect.Bottom - rect.Top;                   //窗口的高度
            int x = rect.Left;
            int y = rect.Top;

            Console.WriteLine(width);

            var w = width/10;
            var h = 10;
            for (var j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    Thread.Sleep(100);
                    Console.Write("*");
                }
                Console.WriteLine();
                //Thread.Sleep(1000);
            }
            Console.Read();
            return;

            int timeout = 2000;
            Stopwatch watch = new Stopwatch();
            watch.Start();
            try
            {
                IWebProxy webProxy = new WebProxy("http://127.0.0.1:8089", true);
                //IWebProxy webProxy = new WebProxy();
                string resl = HttpUtil.Post("http://activityadmin.ymatou.cn/JsonData/CreateSubsidy", "{\"productInActivityIds\":[284393],\"subsidyType\":2}", Encoding.UTF8, timeout, webProxy);

                //string resl = HttpUtil.Post("http://prodlist.iapi.ymatou.com/api/Product/GetProductDetailListByTradeIsolation", "{\"ProductIdList\":[\"64aa9374-4fef-4e26-8fd1-01c8155c8a52\"],\"AppId\":\"activityadmin.ymatou.cn\"}", Encoding.UTF8, timeout, webProxy);

                Console.WriteLine("data:" + resl);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("timespan:" + watch.ElapsedMilliseconds.ToString("N0") + "ms");
            }

            Console.Read();
        }
    }
}
